package org.hyl.javabase.经典集合;

import java.util.List;
import java.util.Scanner;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;

public class demo {
	
	@Before
	public void setUp() throws Exception {
		// demo p=new demo();
	}

	
	@Test
	public void fun1(){
		//从应用的角度 理解和记住它 
		//泛型的第一个优势 作为数组可读性很好
		HashMap<String,Integer> v = new HashMap<String,Integer> ();
		v.put("语文", 80);
		v.put("数学", 81);
		v.put("英语", 82);
		
		System.out.println(v.get("语文"));
		System.out.println(v.get("数学"));
		System.out.println(v.get("英语"));
	}
	public void fun1_2(){
		int []arr =new int[3];
		 arr[0]=80;
		 arr[1]=81;
		 arr[2]=82;
		//数组的 可读性非常差
	}
	
	public void fun2(){
		//泛型集合是一种可变类型的动态数组
		List<String> l = new ArrayList<String> ();
		l.add("小红");
		l.add("小明");
		l.add("小康");
		l.add("小康2");
		l.add(1, "小周");
		

		
		System.out.println(	l.indexOf("小康"));	
		for(String a :l)
			System.out.println(a);

	}
	public void fun2_2(){
		String[] arr1=new String[4];
		arr1[0]="xh";
		arr1[1]="xm";
		arr1[2]="xk";
		
		
		arr1[3]=arr1[2];
		arr1[2]=arr1[1];
		arr1[1]="xz";
		
		
		String[] arr2=new String[4];
		arr2[0]=arr1[0];	
		arr2[1]="xz";
		
		
		arr2[2]=arr1[1];
		arr2[3]=arr1[2];	
		
		for (int i=1;i<3;i++){
			arr2[i+1]=arr1[i];			
		}

		for(String a :arr2)
			System.out.println(a);
    }	
	
	public void fun3_1(){
		Scanner s=	new Scanner(System.in);
		System.out.println("请输入a：");
		int a=s.nextInt();
		System.out.println("请输入b：");
		int b=s.nextInt();
		fun3_2( a, b);
	}
	public void fun3_2(int a,int b){
		int gys=0 ,gbs=0;
		for (int i=(a<b?a:b); i>0;i--)
			if ((a%i==0)&&(b%i==0)) //1
			{
				gys=i;
				break;			
			}

		for(int i=(a<b?b:a);i<=b*a;i++){
			if ((i%a==0)&&(i%b==0)) //1
			{
				gbs=i;
				break;			
			}	
		}
		System.out.println("a="+a+",b="+b+"的 最大公因数="+gys+"; 最小公倍数="+gbs);
		
	}
	
	
	
	public  int gcd(int m, int n)
	{
		while (true)
		{
		 if ((m = m % n) == 0) return n; 
		 if ((n = n % m) == 0) return m;
		}
	}
	
	public void charcode(char c){
		
		System.out.println((int)c);
	}
	public void fun4(){
		charcode('0');
		
	}
		
}
